package com.emperor.controller.vmservice;


import com.emperor.dto.SkuClassSaveDto;
import com.emperor.result.Result;
import com.emperor.service.SkuClassService;
import com.emperor.vo.SkuClassIdVo;
import com.emperor.vo.SkuClassPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/vm-service/skuClass")
@Api(tags = "分类管理")
public class SkuClassController {
    @Autowired
    private SkuClassService skuClassService;

    /**
     * 新增分类
     *
     * @param dto
     * @return
     */
    @ApiOperation("新增分类")
    @PostMapping
    public Result save(@RequestBody SkuClassSaveDto dto) {
        skuClassService.save(dto);
        return Result.success();
    }

    /**
     * 分类搜索
     *
     * @return
     */
    @ApiOperation("分类搜索")
    @GetMapping("/search")
    public Result<SkuClassPageVo> findAll(Integer pageIndex, Integer pageSize, String className) {
        SkuClassPageVo vo = skuClassService.findAll(pageIndex, pageSize, className);
        return Result.success(vo);
    }

    /**
     * 获取分类基本信息
     *
     * @param classId
     * @return
     */
    @ApiOperation("获取分类基本信息")
    @GetMapping("/{classId}")
    public Result<SkuClassIdVo> getById(@PathVariable Integer classId) {
        SkuClassIdVo vo = skuClassService.getById(classId);
        return Result.success(vo);
    }

    /**
     * 修改分类
     * @param classId
     * @param dto
     * @return
     */
    @ApiOperation("修改分类")
    @PutMapping("/{classId}")
    public Result updateById(@PathVariable Integer classId, @RequestBody SkuClassSaveDto dto) {
        skuClassService.updateById(classId, dto);
        return Result.success();
    }
    @ApiOperation("删除分类")
    @DeleteMapping("/{classId}")
    public Result deleteById(@PathVariable Integer classId) {
        skuClassService.deleteById(classId);
        return Result.success();
    }
}
